package com.kkd.kkdapp.view;

import com.kkd.kkdapp.utils.SystemUtils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

public class MyProgressbar extends ProgressBar {

	private Context context;
	private Paint paint;

	public MyProgressbar(Context context) {
		super(context);
		this.context = context;
		paint = new Paint();
	}

	public MyProgressbar(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
		paint = new Paint();
	}

	public MyProgressbar(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		this.context = context;
		paint = new Paint();
	}

	@SuppressLint("DrawAllocation")
	@Override
	protected synchronized void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		paint.setStyle(Paint.Style.FILL_AND_STROKE);
		paint.setAntiAlias(true); // �����
		int progress = getProgress();
		// Log.e("TAG", "progress-->" + progress);
		int max = getMax();
		// Log.e("TAG", "max-->" + max);
		int width = getWidth();
		// Log.e("TAG", "width-->" + width);
		double mProgress = (double) progress / max;
		// Log.e("TAG", "mProgress-->" + mProgress);
		float x = (float) (width * mProgress);
		// Log.e("TAG", "x-->" + x);
		if (mProgress == 0) {
			paint.setColor(Color.rgb(255, 178, 86));
		} else if (0 < mProgress && mProgress < 1) {
			paint.setColor(Color.rgb(255, (int) (178 - 41 * mProgress) + 5,
					(int) (86 - 65 * mProgress) + 6));
			// Log.e("TAG", "(int) (178 - 41 * mProgress) + 3-->"
			// + ((int) (178 - 41 * mProgress) + 3));
			// Log.e("TAG", "(int) (86 - 65 * mProgress) + 4-->"
			// + ((int) (86 - 65 * mProgress) + 4));
			canvas.drawCircle(x, SystemUtils.dip2px(context, 3),
					SystemUtils.dip2px(context, 3), paint);
		} else if (mProgress == 1) {
			paint.setColor(Color.rgb(255, 137, 21));
		}
	}
}
